package com.buer.storage.common.utils;

import org.springframework.web.multipart.MultipartFile;
import sun.misc.BASE64Decoder;

import java.io.IOException;

/**
 * @ProjectName: healthCare-parent
 * @Package: com.zh.common.utils
 * @ClassName: MultipartFileUtils
 * @Description: java类作用描述
 * @Author: lds
 * @CreateDate: 2019/6/4 0004 17:07
 * @UpdateUser: 更新者
 * @UpdateDate: 2019/6/4 0004 17:07
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class MultipartFileUtils {

    public static MultipartFile base64toMultipart(String data, String fileName) throws IOException {

            String[] baseStrs = data.split(",");
            BASE64Decoder decoder = new BASE64Decoder();
            byte[] b = decoder.decodeBuffer(baseStrs[1]);
            for(int i = 0; i < b.length; ++i) {
                if (b[i] < 0) {
                    b[i] += 256;
                }
            }
            return new Base64MultipartFile(b, baseStrs[0] , fileName);
    }
}
